﻿@using LeadMaster.Helpers
@using LeadMaster.Properties
@using LeadMaster.Controllers;
@using PagedList.Mvc;
@using PagedList;

@model LeadMaster.ViewModels.ViewModelClient

<style type="text/css">
.InfoRowHeight
{
    height: 20px;   
}
.sectionheader
{
    font-size: 9px;
    text-align: left;
}
.topsectiontitles
{
 
    text-align: left;
    background-color: #BFFFFF;
}
.statusdropdown
{
    font-family: Trebuchet MS;
    letter-spacing: .1em;
    font-size:14px;
}
</style>

<div class="spacer"></div>

@if (@Model.FullListLeadResults != null && @Model.FullListLeadResults.Count() > 0)
{
<div class="spacer"></div>
<table style="width:2500px;">
<tr>
<th>&nbsp;</th>
@for (int i = 0; i < @Model.GridTitlesList.Count(); i++)
{
    <th>
    <label style="color: #FF0000; font-size: 9px; font-family: Arial, Helvetica, sans-serif; font-weight: bold;">
    @if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion != null && Model.FullListLeadResults[i].LeadResult.LeadGroupQuestionsID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.ClientNote != null)
        {
            @Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.ClientNote
        }
    }
    </label>
    </th>    
}
<th>&nbsp;</th>
<th>&nbsp;</th>
<th style="width: 300px;">&nbsp;</th>
</tr>

<tr>
<th style="background-color: #@(Model.GridTitlesList.FirstOrDefault().Backcolour);">&nbsp;</th>
@{
int colSpan = 1;
string blockTitle = "";
string backColour = "";
for (int i = 0; i < @Model.GridTitlesList.Count(); i++)
{
    if (Model.FullListLeadResults[i].LeadResult.LeadStatQuestion != null && Model.FullListLeadResults[i].LeadResult.LeadStatQuestionsID > 0)
    {
        if (blockTitle == Model.FullListLeadResults[i].LeadResult.LeadStatQuestion.LeadStat.Title)
        {
            colSpan++;

        }
        else
        {
            if (blockTitle.Trim().Length > 0)
            {
                <th colspan="@(colSpan)" class="topsectiontitles" style="background-color: #@(backColour);"><label class="sectionheader">@blockTitle</label></th>                    
            }
            colSpan = 1;
            backColour = Model.GridTitlesList[i].Backcolour;
            blockTitle = Model.FullListLeadResults[i].LeadResult.LeadStatQuestion.LeadStat.Title;
        }
    }
    if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion != null && Model.FullListLeadResults[i].LeadResult.LeadGroupQuestionsID > 0)
    {
        if (blockTitle == Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.LeadGroups.Title)
        {
            colSpan++;
        }
        else
        {
            if (blockTitle.Trim().Length > 0)
            {
                <th colspan="@(colSpan)" class="topsectiontitles" style="background-color: #@(backColour);"><label class="sectionheader">@blockTitle</label></th>                
            }
            colSpan = 1;
            backColour = Model.GridTitlesList[i].Backcolour;
            blockTitle = Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.LeadGroups.Title;
        }
    }
} 
<th colspan="@(colSpan)" class="topsectiontitles" style="background-color: #@(backColour);"><label class="sectionheader">@blockTitle</label></th>
}
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
</tr>
<tr>
<th style="background-color: #@(Model.GridTitlesList.FirstOrDefault().Backcolour);">&nbsp;</th>
@for (int i = 0; i < @Model.GridTitlesList.Count(); i++)
{
    <th style="background-color: #@(Model.GridTitlesList[i].Backcolour); ">
    <label style="color: #FF0000;">
    @if (Model.FullListLeadResults[i].LeadResult.LeadStatQuestion != null && Model.FullListLeadResults[i].LeadResult.LeadStatQuestionsID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.LeadStatQuestion.Mandatory == true)
        {
            @:M
        }
        else
        {
            @:I
        }
    }
    @if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion != null && Model.FullListLeadResults[i].LeadResult.LeadGroupQuestionsID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.Mandatory == true)
        {
            @:M
        }
        else
        {
            @:I
        }
    }
    </label>
    </th>    
}
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
</tr>
<tr>
<th style="border: 1px solid #000000; background-color: #999999;"><label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">Ref</label></th>
@for (int i = 0; i < @Model.GridTitlesList.Count(); i++)
{
    <th style="border: 1px solid #000000; background-color: #BFBFBF;">
    <label style="color: #2a1915; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
    @Model.GridTitlesList[i].Title
    </label>
    </th>    
}
<th style="border: 1px solid #000000; background-color: #BFBFBF;">
<label style="color: #2a1915; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Current Status
</label>
</th>
<th style="border: 1px solid #000000; background-color: #BFBFBF;">
<label style="color: #2a1915; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Status Notes
</label>
</th>
<th style="border: 1px solid #000000; background-color: #BFBFBF;">
<label style="color: #2a1915; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Responsibility
</label>
</th>
</tr>
<tr style="@(ClientController.GetColourCode(Model.FullListLeadResults.FirstOrDefault().LeadFlag))">
@{
int iCounter = 0;
bool firstRow = true;
string poID = string.Empty;
bool startOfSequence = true;
bool finishSequence = false;
string colourCode = ClientController.GetColourCode(Model.FullListLeadResults.FirstOrDefault().LeadFlag);

foreach (var item in ViewBag.LeadsPage)
{
    if (startOfSequence)
    {
        @:<td style="border: 1px solid #000000;"><label style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;">@item.LeadStatus.BlockID / @item.LeadStatus.CallCentre.CallCentreID / <br />@item.LeadStatus.CallCentre.Classification</label></td>
        startOfSequence = false;
    }
    if (iCounter == item.LeadResult.QuestionBlock || finishSequence)
    {
        @:</tr><tr style="width: 25px; height: 25px"  id="row@(item.LeadStatus.BlockID)">
        @:<td style="border: 1px solid #000000;"><label style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;">@item.LeadStatus.BlockID / @item.LeadStatus.CallCentre.CallCentreID / <br />@item.LeadStatus.CallCentre.Classification</label></td>
        iCounter = 0;
        finishSequence = false;
    }
    <td style="border: 1px solid #000000;">
    @if ((item.LeadResult.Answer == "Free" || item.LeadResult.Answer == "Paid") && Session["PersonType"].ToString() == "C")
    {
        <text>
        <select class="freepaid" id="freepaid@(item.LeadStatus.LeadStatusID)" data-leadstatusid="@(item.LeadStatus.LeadStatusID)">
        <option value="Paid"
        @if (item.LeadResult.Answer == "Paid")
        {
		 @:selected
	    }>Paid</option>
        <option value="Free" 
        @if (item.LeadResult.Answer == "Free")
        {
		 @:selected
	    }>Free</option>
        </select>
        </text>
    }
    else
    {
        <text>
        <label style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; @(colourCode)" >
        @item.LeadResult.Answer
        </label>
        </text>
    }
    </td>
    iCounter++;
    if (iCounter == item.LeadResult.QuestionBlock)
    {
        finishSequence = true;
        <text>
            <td style="border: 1px solid #000000;" >
            <input type="hidden" name="LeadDate" value="@(item.LeadStatus.LeadDate)" />
            @if (Session["PersonType"].ToString() != "E")
            {
                <select data-id="@(item.LeadResult.LeadResultsID)" id="flag_@(item.LeadStatus.LeadID)_@(item.LeadStatus.BlockID)" data-leadstatusid="@(item.LeadStatus.LeadStatusID)"
                    style="color: #@(item.LeadFlag.TextColour); font-family: 'Trebuchet MS'; font-size: 12px; font-weight: bold; letter-spacing: .1em;" class="statusdropdown"  >
                @foreach (var leadFlag in Model.ListLeadFlags)
                {
                <option value="@(leadFlag.LeadFlagsID)" style="color: #@(leadFlag.TextColour);"
                @if (item.LeadStatus.LeadFlagsID == leadFlag.LeadFlagsID)
                {
		        @:selected
	            }
                >@leadFlag.Description</option>    
                }
                </select>
                <br />
            }
            @if (Session["PersonType"].ToString() == "C")
            {
                <select class="funding" id="funding@(item.LeadStatus.LeadStatusID)" data-leadstatusid="@(item.LeadStatus.LeadStatusID)">
                <option value="Funding Status"
                @if (item.LeadStatus.Funding == "Funding Status")
                {
		        @:selected
	            }>Funding Status</option>
                <option value="Funding Applied For"
                @if (item.LeadStatus.Funding == "Funding Applied For")
                {
		        @:selected
	            }>Funding Applied For</option>
                <option value="Funding Confirmed"
                @if (item.LeadStatus.Funding == "Funding Confirmed")
                {
		        @:selected
	            }>Funding Confirmed</option>
                <option value="Funding Denied"
                @if (item.LeadStatus.Funding == "Funding Denied")
                {
		        @:selected
	            }>Funding Denied</option>
                </select>
            }
            @if ((item.LeadStatus.LeadFlag.WithInstaller == true || item.LeadStatus.LeadFlag.WithDeaGda == true) && item.LeadStatus.LeadFlag.Description.Substring(0, 9) == "Passed To")
            {
                <br />
                <select class="handover" id="handover@(item.LeadStatus.LeadStatusID)" data-leadstatusid="@(item.LeadStatus.LeadStatusID)">
                <option value="In Progress"
                @if (item.LeadStatus.Handover == "In Progress")
                {
		            @:selected
	            }>In Progress</option>
                <option value="Completed"
                @if (item.LeadStatus.Handover == "Completed")
                {
		            @:selected
	            }>Completed</option>
                </select>
            }
            </td>
            <td style="border: 1px solid #000000;">
                <textarea id="statusnote@(item.LeadStatus.LeadStatusID)" class="savenote" data-leadstatusid="@(item.LeadStatus.LeadStatusID)"  style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; cursor: pointer; width:300px; height: 80px; !important" readonly>@item.LeadStatus.Notes</textarea><br />
                <input type="button" value="New Note" data-leadstatusid = "@(item.LeadStatus.LeadStatusID)" id="savenote@(item.LeadStatus.LeadStatusID)" class="savenotebutton" style="font-size: 9px;" data-leadstatusid="@(item.LeadStatus.LeadStatusID)" />
                <input type="button" value="Refresh" data-leadstatusid = "@(item.LeadStatus.LeadStatusID)" id="refreshnote@(item.LeadStatus.LeadStatusID)" class="refreshnotebutton" style="font-size: 9px;" data-leadstatusid="@(item.LeadStatus.LeadStatusID)" />
            </td>
            <td style="border: 1px solid #000000;">
                @if (Session["PersonType"].ToString() == "C")
                {
                    <label>Installer</label>
		            <select class="selectresponsibility" data-leadstatusid = "@(item.LeadStatus.LeadStatusID)" id="installer@(item.LeadStatus.LeadStatusID)" >
                    <option value="0">Select Installer</option>
                    @foreach (var installer in Model.ListInstallers)
                    {
		            <option value="@(installer.CallCentreID)" 
                    @if (item.LeadStatus.ResponsibleID == installer.CallCentreID)
                    {
                        @:selected
	                }
                    >@installer.CallCentre</option>
                    }
                    </select>
                    <br />
                    <label>DEA/GDA</label>
                    <select class="selectdeagda" data-leadstatusid = "@(item.LeadStatus.LeadStatusID)"  id="deagda@(item.LeadStatus.LeadStatusID)" >
                    <option value="0">Select DEA/GDA</option>
                    @foreach (var deagda in Model.ListDeaGda)
                    {
		            <option value="@(deagda.CallCentreID)"
                    @if (item.LeadStatus.DeaGdaID == deagda.CallCentreID)
                    {
                        @:selected
	                }
                    >@deagda.CallCentre</option>
                    }
                    </select>
                }
                else if (Session["PersonType"].ToString() == "N")
                {
                    <label>Engineer</label>
		            <select class="selectresponsibility" data-leadstatusid = "@(item.LeadStatus.LeadStatusID)" id="installer@(item.LeadStatus.LeadStatusID)" >
                    <option value="0">Select Engineer</option>
                    @foreach (var engineer in Model.ListEngineers)
                    {
		            <option value="@(engineer.CallCentreID)" 
                    @if (item.LeadStatus.ResponsibleID == engineer.CallCentreID)
                    {
                        @:selected
	                }
                    >@engineer.CallCentre</option>
                    }
                    </select>
                 }
                 else if (Session["PersonType"].ToString() == "O")
                 {
                    <label>Classification</label>
		            <select class="classification" data-leadstatusid = "@(item.LeadStatus.LeadStatusID)" id="classification@(item.LeadStatus.ClassificationID)" >
                    <option value="0">Select Classification</option>
                    @if (item.LeadStatus.Classification.NU_New ?? false==true)
                    {
                    <option value="NU_New" @(item.LeadStatus.SelectedClassification=="NU_New" ? "selected" : "")>NU_New</option>    
                    }  
		            @if (item.LeadStatus.Classification.NU_Research ?? false == true)
                    {
                    <option value="NU_Research" @(item.LeadStatus.SelectedClassification=="NU_Research" ? "selected" : "")>NU_Research</option>    
                    }  
                    @if (item.LeadStatus.Classification.NU_Past ?? false == true)
                    {
                    <option value="NU_Past" @(item.LeadStatus.SelectedClassification=="NU_Past" ? "selected" : "")>NU_Past</option>    
                    }  
                    @if (item.LeadStatus.Classification.NU_Face ?? false == true)
                    {
                    <option value="NU_Face" @(item.LeadStatus.SelectedClassification=="NU_Face" ? "selected" : "") >NU_Face</option>    
                    }  
                    @if (item.LeadStatus.Classification.U_New ?? false == true)
                    {
                    <option value="U_New" @(item.LeadStatus.SelectedClassification=="U_New" ? "selected" : "")>U_New</option>    
                    }  
                    @if (item.LeadStatus.Classification.U_Research ?? false == true)
                    {
                    <option value="U_Research" @(item.LeadStatus.SelectedClassification=="U_Research" ? "selected" : "")>U_Research</option>    
                    }  
                    @if (item.LeadStatus.Classification.U_Past ?? false == true)
                    {
                    <option value="U_Past" @(item.LeadStatus.SelectedClassification == "U_Past" ? "selected" : "")>U_Past</option>    
                    }  
                    @if (item.LeadStatus.Classification.U_Face ?? false == true)
                    {
                    <option value="U_Face" @(item.LeadStatus.SelectedClassification == "U_Face" ? "selected" : "")>U_Face</option>    
                    }  
                    </select>         
                 }
            </td>
            <td>
            <a href="http://webellas.arvixevps.com/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2forac%2fAdministrator%2fdunsmore%2fClientWorkSheet&rs:Command=Render&leadid=@(item.LeadResult.LeadID)&blockid=@(item.LeadResult.BlockId)&rc:Parameters=false" target="_blank">
             &nbsp; <!--<img src="~/Images/workplan.png" style="height:25px; width: 25px;"/>-->
            </a>
            </td>
            <td>
	        @if (item.LeadStatus.Lead.StreetView == true)
         {
            <a style='font-family: Arial, Helvetica, sans-serif; font-size: 9px; font-style: italic; color: #800080' href='https://www.google.co.uk/maps/place/@(QCController.StreetviewPostcode(item.LeadStatus.LeadStatusID))' target='_blank'>StreetView</a>
             <br />
         }
            <a style='font-family: Arial, Helvetica, sans-serif; font-size: 9px; font-style: italic; color: #800080' href="http://webellas.arvixevps.com/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2forac%2flye%2fClientWorkSheet&rs:Command=Render&leadid=@(item.LeadStatus.LeadID.ToString())&blockid=@(item.LeadStatus.BlockID.ToString())" target="_blank">Worksheet</a>
            <br />
            </td>
            
        </text>
    }
}

}
</tr>
</table>
}
else
{
<h3>No Leads found.</h3>
}
<div id="myPager">
@Html.PagedListPager((IPagedList)ViewBag.LeadsPage, page => Url.Action("FetchLeadBlock") + "/?leadID=" + ViewBag.id + "&surname=" + ViewBag.surname + "&telephone=" + ViewBag.telephone + "&postcode=" + ViewBag.postcode + "&dayfilter=" + ViewBag.dayfilter + "&leadref=" + ViewBag.leadref + "&leadFilter=" + ViewBag.leadFilter + "&agent=" + ViewBag.selectedagent + "&regionid=" + ViewBag.selectedregion + "&classification=" + ViewBag.classification + "&page=" + page)
</div>

<div id="changestatus"></div>
<div id="changereason"></div>
<div id="escalate"></div>
<div id="osnote"></div>
<input type="hidden" id="selectedelement" value="" />

<script type="text/javascript">
    $(document).ready(function () {

        runEffect();

        $(".hidethese").hide();

          function runEffect() {
          // get effect type from
          var selectedEffect = "shake";
 
          // most effect types need no options passed by default
          var options = {};
          // some effects have required parameters
          if ( selectedEffect === "scale" ) {
            options = { percent: 0 };
          } else if ( selectedEffect === "transfer" ) {
            options = { to: "#button", className: "ui-effects-transfer" };
          } else if ( selectedEffect === "size" ) {
            options = { to: { width: 200, height: 60 } };
          }
 
          // run the effect
          $( ".blinker" ).effect( selectedEffect, options, 500, callback );
        };

        $("#osnote").dialog(
        {
            autoOpen: false,
            width: 600,
            open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
            position: ['middle', 20],
            modal: true,
            dialogClass: 'notitle',
            buttons: {
                save: function () {
                    $(this).dialog("close");
                    $("#formClientNote").submit();
                },
                cancel: function () {
                    $(this).dialog("close");
                }
            }
        });

        function callback() {
            setTimeout(function() {
                $( ".blinker" ).removeAttr( "style" ).hide().fadeIn();
            }, 1000 );
        };

        $("escalate").dialog({
            autoOpen: false,
            width: 600,
            open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
            position: ['middle', 20],
            modal: true,
            dialogClass: 'notitle',
            buttons: {
                Send: function () {
                    $(this).dialog("close");
                    $("#formEscalate").submit();
                    $($("#selectedelement").val()).toggle();
                },
                cancel: function () {
                    $(this).dialog("close");
                }
            }
        });

        $(".changeleadstatus").click(function () {
            var id = $(this).data("id");
            $("#selectedelement").val($(this).attr("id"));
            $("#changestatus").dialog("open");
            $('#changestatus').html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            var contactURL = '@(Url.Action("ChangeLeadStatus", "Client"))/?id=' + $(this).data("id") + '&element=' + $(this).attr("id") + "&index=";
            $('#changestatus').load(contactURL);
        });

        $(".changeleadreason").click(function () {
            $("#selectedelement").val($(this).attr("id"));
            $("#changereason").dialog("open");
            $('#changereason').html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            var contactURL = '@(Url.Action("ChangeLeadReason", "Client"))/?id=' + $(this).data("id") + "&index=";
            $('#changereason').load(contactURL);
        });

        $(".statusdropdown").change(function() {
        var leadStatusID=$(this).data("leadstatusid");
        $.ajax({
                type: "GET",
                url: '@(Url.Action("ChangeLeadStatus", "Client"))/?leadstatusid=' + $(this).data("leadstatusid") + "&statusvalue=" + $(this).val()
            });
        });

        $(".funding").change(function() {
        var leadStatusID=$(this).data("leadstatusid");
        $.ajax({
                type: "GET",
                url: '@(Url.Action("ChangeFunding", "Client"))/?leadstatusid=' + leadStatusID + "&fundingvalue=" + $(this).val()
            });
        });

        $(".handover").change(function() {
        var leadStatusID=$(this).data("leadstatusid");
        $.ajax({
                type: "GET",
                url: '@(Url.Action("ChangeHandover", "Client"))/?leadstatusid=' + $(this).data("leadstatusid") + "&handovervalue=" + $(this).val()
            });
        });

        $(".freepaid").change(function() {
        var leadStatusID=$(this).data("leadstatusid");
        $.ajax({
                type: "GET",
                url: '@(Url.Action("FreePaid", "Client"))/?leadstatusid=' + leadStatusID + "&freePaid=" + $(this).val()
            });
        });

        $(".dead").click(function() {
        alert($(this).val());
        var leadStatusID=$(this).data("leadstatusid");
        $.ajax({
                type: "GET",
                url: '@(Url.Action("Dead", "Client"))/?leadstatusid=' + $(this).data("leadstatusid") + "&deadvalue=" + $(this).val()
            });
        });

        $(".savenotebutton").click(function() {
            var leadStatusID=$(this).data("leadstatusid");
            $("#osnote").dialog("open");
            $('#osnote').html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            var contactURL = '@(Url.Action("NewNote", "Client"))/?id=' + leadStatusID;
            $('#osnote').load(contactURL);

        });

        $(".refreshnotebutton").click(function() {
         var NoteToUpdate=$("#statusnote" + $(this).data("leadstatusid"));
         $.ajax({
                type: "GET",
                url: '@(Url.Action("FetchClientNote", "Client"))/?leadStatusID=' + $(this).data("leadstatusid") ,
                success: function(data){
                NoteToUpdate.val(data);
                }
                });
        });

        $(".selectresponsibility").change(function() {
            $.ajax({
                type: "GET",
                url: '@(Url.Action("SaveResponsibility", "Client"))/?leadStatusID=' + $(this).data("leadstatusid") + "&installerID=" + $(this).val()
                });
        });

        $(".classification").change(function() {
            $.ajax({
                type: "GET",
                url: '@(Url.Action("SaveClassification", "Client"))/?leadStatusID=' + $(this).data("leadstatusid") + "&selectedclassification=" + $(this).val()
                });
        });

        $(".selectdeagda").change(function() {
            $.ajax({
                type: "GET",
                url: '@(Url.Action("SaveDeaGda", "Client"))/?leadStatusID=' + $(this).data("leadstatusid") + "&installerID=" + $(this).val()
                });
        });
        
        function successfunc(data, elementToUpdate) {
            $("#" + elementToUpdate).text(data);
            if(data=="Lead Rejected")
            {
            elementToUpdate="#" + elementToUpdate.replace("flag","reas") ;
            $(elementToUpdate).attr("class","changeleadreason");
            $("#selectedelement").val(elementToUpdate.substring(1));
            $("#changereason").dialog("open");
            $('#changereason').html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            var contactURL = '@(Url.Action("ChangeLeadReason", "Client"))/?id=' + $(elementToUpdate).data("id") + "&index=";
            $('#changereason').load(contactURL);
            }
        }

        function UpdateElement(elementToUpdate)
        {
            var ans=confirm("Status Changed")
            if (ans==true) {
            $.ajax({
                type: "GET",
                url: "@(Url.Action("UpdateElement", "Client"))/?currentElement=" + elementToUpdate.replace(/["]/g, "'"),
                success: function(data){
                successfunc(data, elementToUpdate.replace(/["]/g, ""));
                }
            });
            }
        }

        function UpdateReason(elementToUpdate)
        {
            var ans=confirm("Reason Allocated, Thank You")
            if (ans==true) {
                var ElementUpdate={};
                ElementUpdate.currentElement=elementToUpdate.replace(/["]/g, "'");
                $.getJSON("UpdateReason",ElementUpdate,function(data)
                {
                $("#" + data.elementToUpdate).text(data.theReason);
                $("#" + data.noteToUpdate).text(data.theNote);
                });
            }
        }
    });
</script>

